﻿using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using MVVMLightDemo.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace MVVMLightDemo.ViewModel
{
    public class UseControlViewModel:ViewModelBase
    {
        public RelayCommand<string> SendFavoriteCommand { get; set; }

        private string showFavorite;

        public string ShowFavorite
        {
            get { return showFavorite; }
            set
            {
                showFavorite = value;
                this.RaisePropertyChanged("ShowFavorite");
            }
        }

        private Employee showEmployee;

        public Employee ShowEmployee
        {
            get { return showEmployee; }
            set
            {
                showEmployee = value;
                this.RaisePropertyChanged("ShowEmployee");
            }
        }

        public RelayCommand<Employee> SubmitEmployeeCommand { get; set; }

        private string filePath;

        public string FilePath
        {
            get { return filePath; }
            set
            {
                filePath = value;
                this.RaisePropertyChanged("FilePath");
            }
        }

        private List<Fruit> listFruit;

        public List<Fruit> ListFruit
        {
            get { return listFruit; }
            set
            {
                listFruit = value;
                this.RaisePropertyChanged("ListFruit");
            }
        }

        private int selectedIndex;

        public int SelectedIndex
        {
            get { return selectedIndex; }
            set
            {
                selectedIndex = value;
                this.RaisePropertyChanged("SelectedIndex");
            }
        }

        private string selectedInfo;

        public string SelectedInfo
        {
            get { return selectedInfo; }
            set
            {
                selectedInfo = value;
                this.RaisePropertyChanged("SelectedInfo");
            }
        }

        public RelayCommand SelectedChangedCommand { get; set; }



        public RelayCommand<DragEventArgs> DragCommand { get; set; }

        public UseControlViewModel()
        {
            SendFavoriteCommand = new RelayCommand<string>((p) =>
            {
                ShowFavorite = p;
            });

            SubmitEmployeeCommand = new RelayCommand<Employee>((p)=>
            {
                ShowEmployee = p;
            });

            DragCommand = new RelayCommand<DragEventArgs>((e)=>
            {
                FilePath = ((System.Array)e.Data.GetData(System.Windows.DataFormats.FileDrop)).GetValue(0).ToString();
            });

            ListFruit = new List<Fruit> {
                new Fruit{Name = "Apple",Category="Water_full",Price = Faker.RandomNumber.Next(5,10).ToString()},
                new Fruit{Name = "Banana",Category="Water_full",Price = Faker.RandomNumber.Next(5,10).ToString()},
                new Fruit{Name = "Cherry",Category="Water_full",Price = Faker.RandomNumber.Next(5,10).ToString()},
                new Fruit{Name = "Watermelon",Category="Water_full",Price = Faker.RandomNumber.Next(5,10).ToString()},
                new Fruit{Name = "Orange",Category="Water_full",Price = Faker.RandomNumber.Next(5,10).ToString()},
                new Fruit{Name = "Tomato",Category="Water_full",Price = Faker.RandomNumber.Next(5,10).ToString()},
                new Fruit{Name = "Juice",Category="Water_full",Price = Faker.RandomNumber.Next(5,10).ToString()},
            };

            SelectedChangedCommand = new RelayCommand(()=>
            {
                SelectedInfo = ListFruit[SelectedIndex].Name;
            });
        }


    }
}
